//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "FloatingRateCoupon.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Indexes/InterestRateIndex.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Cashflows/FloatingRateCouponPricer.h>
#include <gen/QL/Cashflows/Coupon.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (DateTime paymentDate, Double nominal, DateTime startDate, DateTime endDate, UInt32 fixingDays, Cephei::QL::Indexes::IInterestRateIndex^ index, Microsoft::FSharp::Core::FSharpOption<Double>^ gearing, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodStart, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodEnd, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isInArrears, Cephei::QL::Cashflows::IFloatingRateCouponPricer^ QL_Pricer) : CCoupon(CFloatingRateCoupon::typeid)
{
    CInterestRateIndex^ _Cindex;
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phFloatingRateCoupon = NULL;
#endif
        QuantLib::Date _paymentDate = (QuantLib::Date)ValueHelper::Convert (paymentDate);
        QuantLib::Real _nominal = (QuantLib::Real)ValueHelper::Convert (nominal);
        QuantLib::Date _startDate = (QuantLib::Date)ValueHelper::Convert (startDate);
        QuantLib::Date _endDate = (QuantLib::Date)ValueHelper::Convert (endDate);
        QuantLib::Natural _fixingDays = (QuantLib::Natural)ValueHelper::Convert (fixingDays);
        _Cindex = safe_cast<CInterestRateIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::InterestRateIndex>& _index = static_cast<boost::shared_ptr<QuantLib::InterestRateIndex>&> (_Cindex->GetShared ()); 
        QuantLib::Real _gearing = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (gearing) ? (QuantLib::Real)ValueHelper::Convert (gearing->Value) : 1.0); //4
        QuantLib::Spread _spread = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (spread) ? (QuantLib::Spread)ValueHelper::Convert (spread->Value) : 0.0); //4
        QuantLib::Date _refPeriodStart = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (refPeriodStart) ? (QuantLib::Date)ValueHelper::Convert (refPeriodStart->Value) : QuantLib::Date()); //4
        QuantLib::Date _refPeriodEnd = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (refPeriodEnd) ? (QuantLib::Date)ValueHelper::Convert (refPeriodEnd->Value) : QuantLib::Date()); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter))
        {
            _CdayCounter = safe_cast<CDayCounter^> (dayCounter->Value);
            _CdayCounter->Lock();
        }
        QuantLib::DayCounter& _dayCounter = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter) ? static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()) : QuantLib::DayCounter()); //1
        bool _isInArrears = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isInArrears) ? (bool)ValueHelper::Convert (isInArrears->Value) : false); //4
        _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (new QuantLib::FloatingRateCoupon ( _paymentDate,  _nominal,  _startDate,  _endDate,  _fixingDays,  _index,  _gearing,  _spread,  _refPeriodStart,  _refPeriodEnd,  _dayCounter,  _isInArrears ));
        CFloatingRateCouponPricer^ _CQL_Pricer = safe_cast<CFloatingRateCouponPricer^> (QL_Pricer);
        boost::shared_ptr<QuantLib::FloatingRateCouponPricer>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::FloatingRateCouponPricer>&> (_CQL_Pricer->GetShared ());
        (*_ppFloatingRateCoupon)->setPricer (_QL_Pricer);
        SetCoupon (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (boost::shared_ptr<QuantLib::FloatingRateCoupon>& childNative, Object^ owner) : CCoupon(CFloatingRateCoupon::typeid)
{
#ifdef HANDLE
	_phFloatingRateCoupon = NULL;
#endif
	_ppFloatingRateCoupon = &childNative;
    _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
}
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (QuantLib::FloatingRateCoupon& childNative, Object^ owner) : CCoupon(CFloatingRateCoupon::typeid)
{
#ifdef HANDLE
	_phFloatingRateCoupon = NULL;
#endif
	_ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (&childNative);
    _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
    _FloatingRateCouponOwner = owner;
    _CouponOwner = owner;
}

Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (CFloatingRateCoupon^ copy) : CCoupon(CFloatingRateCoupon::typeid)
{
#ifdef HANDLE
	_phFloatingRateCoupon = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (copy->GetShared());
        _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
    }
}
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (System::Type^ t) : CCoupon(CFloatingRateCoupon::typeid)
{
#ifdef HANDLE
	_phFloatingRateCoupon = NULL;
#endif
	if (!t->IsSubclassOf(CFloatingRateCoupon::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (QuantLib::Handle<QuantLib::FloatingRateCoupon>& childNative, Object^ owner)  : CCoupon(CFloatingRateCoupon::typeid)
{
	_phFloatingRateCoupon = &childNative;
	_ppFloatingRateCoupon = &static_cast<boost::shared_ptr<QuantLib::FloatingRateCoupon>>(childNative.currentLink());
    _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
    _FloatingRateCouponOwner = owner;
}
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (QuantLib::Handle<QuantLib::FloatingRateCoupon> childNative)  : CCoupon(CFloatingRateCoupon::typeid)
{
	_phFloatingRateCoupon = &childNative;
	_ppFloatingRateCoupon = &static_cast<boost::shared_ptr<QuantLib::FloatingRateCoupon>>(childNative.currentLink());
    _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CFloatingRateCoupon::CFloatingRateCoupon (QuantLib::FloatingRateCoupon childNative)  : CCoupon(CFloatingRateCoupon::typeid)
{
#ifdef HANDLE
	_phFloatingRateCoupon = NULL;
#endif
	_ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (new QuantLib::FloatingRateCoupon (childNative));
    _ppCoupon = new boost::shared_ptr<QuantLib::Coupon> (boost::dynamic_pointer_cast<QuantLib::Coupon> (*_ppFloatingRateCoupon));
}
#endif

Cephei::QL::Cashflows::CFloatingRateCoupon::~CFloatingRateCoupon ()
{
    if (_ppFloatingRateCoupon != NULL)
    {
	    delete _ppFloatingRateCoupon;
        _ppFloatingRateCoupon = NULL;
    }
}
Cephei::QL::Cashflows::CFloatingRateCoupon::!CFloatingRateCoupon ()
{
    if (_ppFloatingRateCoupon != NULL)
    {
	    delete _ppFloatingRateCoupon;
    }
}
QuantLib::FloatingRateCoupon& Cephei::QL::Cashflows::CFloatingRateCoupon::GetReference ()
{
    if (_ppFloatingRateCoupon == NULL) throw gcnew NativeNullException ();
	return **_ppFloatingRateCoupon;
}
boost::shared_ptr<QuantLib::FloatingRateCoupon>& Cephei::QL::Cashflows::CFloatingRateCoupon::GetShared ()
{
    if (_ppFloatingRateCoupon == NULL) throw gcnew NativeNullException ();
	return *_ppFloatingRateCoupon;
}
QuantLib::FloatingRateCoupon* Cephei::QL::Cashflows::CFloatingRateCoupon::GetPointer ()
{
    if (_ppFloatingRateCoupon == NULL) throw gcnew NativeNullException ();
	return &**_ppFloatingRateCoupon;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FloatingRateCoupon>& Cephei::QL::Cashflows::CFloatingRateCoupon::GetHandle ()
{
	if (_phFloatingRateCoupon == NULL)
	{
		_phFloatingRateCoupon = new Handle<QuantLib::FloatingRateCoupon> (*_ppFloatingRateCoupon);
	}
	return *_phFloatingRateCoupon;
}
#endif
bool Cephei::QL::Cashflows::CFloatingRateCoupon::HasNative () 
{
	return (_ppFloatingRateCoupon != NULL);
}

Double Cephei::QL::Cashflows::CFloatingRateCoupon::AccruedAmount (DateTime d)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFloatingRateCoupon)->accruedAmount ( _d );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::AdjustedFixing::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppFloatingRateCoupon)->adjustedFixing ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::Amount::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFloatingRateCoupon)->amount ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::ConvexityAdjustment::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppFloatingRateCoupon)->convexityAdjustment ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Cashflows::CFloatingRateCoupon::DayCounter::get ()
{
    try
    {
    	QuantLib::DayCounter _rv = (QuantLib::DayCounter)(*_ppFloatingRateCoupon)->dayCounter ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = gcnew Cephei::QL::Times::CDayCounter (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Cashflows::CFloatingRateCoupon::FixingDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppFloatingRateCoupon)->fixingDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Cashflows::CFloatingRateCoupon::FixingDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppFloatingRateCoupon)->fixingDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::Gearing::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFloatingRateCoupon)->gearing ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::IndexFixing::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppFloatingRateCoupon)->indexFixing ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CFloatingRateCoupon::IsInArrears::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppFloatingRateCoupon)->isInArrears ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::Price (Cephei::QL::Termstructures::IYieldTermStructure^ discountingCurve)
{
    CYieldTermStructure^ _CdiscountingCurve;
    try
    {
        _CdiscountingCurve = safe_cast<CYieldTermStructure^> (discountingCurve);
        _CdiscountingCurve->Lock();
        Handle<QuantLib::YieldTermStructure>& _discountingCurve = static_cast<Handle<QuantLib::YieldTermStructure>&> (_CdiscountingCurve->GetHandle ()); 
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFloatingRateCoupon)->price ( _discountingCurve );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CdiscountingCurve != nullptr) _CdiscountingCurve->Unlock();
    }
}
Cephei::QL::Cashflows::IFloatingRateCouponPricer^ Cephei::QL::Cashflows::CFloatingRateCoupon::Pricer::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::FloatingRateCouponPricer> _rv = (boost::shared_ptr<QuantLib::FloatingRateCouponPricer>)(*_ppFloatingRateCoupon)->pricer ( );   
        Cephei::QL::Cashflows::CFloatingRateCouponPricer^ _nrv = gcnew Cephei::QL::Cashflows::CFloatingRateCouponPricer (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::Rate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppFloatingRateCoupon)->rate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::IFloatingRateCoupon^ Cephei::QL::Cashflows::CFloatingRateCoupon::SetPricer (Cephei::QL::Cashflows::IFloatingRateCouponPricer^ pricer)
{
    CFloatingRateCouponPricer^ _Cpricer;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cpricer = safe_cast<CFloatingRateCouponPricer^> (pricer);
        _Cpricer->Lock();
        boost::shared_ptr<QuantLib::FloatingRateCouponPricer>& _pricer = static_cast<boost::shared_ptr<QuantLib::FloatingRateCouponPricer>&> (_Cpricer->GetShared ()); 
    	(*_ppFloatingRateCoupon)->setPricer ( _pricer );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cpricer != nullptr) _Cpricer->Unlock();
    }
}
Double Cephei::QL::Cashflows::CFloatingRateCoupon::Spread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppFloatingRateCoupon)->spread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::IFloatingRateCoupon^ Cephei::QL::Cashflows::CFloatingRateCoupon::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppFloatingRateCoupon)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IInterestRateIndex^ Cephei::QL::Cashflows::CFloatingRateCoupon::Index::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::InterestRateIndex>& _rv = (boost::shared_ptr<QuantLib::InterestRateIndex>&)(*_ppFloatingRateCoupon)->index ( );   
        Cephei::QL::Indexes::CInterestRateIndex^ _nrv = gcnew Cephei::QL::Indexes::CInterestRateIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Cashflows::IFloatingRateCoupon^ Cephei::QL::Cashflows::CFloatingRateCoupon_Factory::Create (DateTime paymentDate, Double nominal, DateTime startDate, DateTime endDate, UInt32 fixingDays, Cephei::QL::Indexes::IInterestRateIndex^ index, Microsoft::FSharp::Core::FSharpOption<Double>^ gearing, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodStart, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodEnd, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isInArrears, Cephei::QL::Cashflows::IFloatingRateCouponPricer^ QL_Pricer)
{
    return gcnew CFloatingRateCoupon ( paymentDate,  nominal,  startDate,  endDate,  fixingDays,  index,  gearing,  spread,  refPeriodStart,  refPeriodEnd,  dayCounter,  isInArrears,  QL_Pricer);
}
